<?php
class ModelNewsletterSubscriber extends Model {
    public function addSubscriber($data) {
        if($this->getByEmail($data['email'])){
            return false;
        }

        $this->db->query("INSERT INTO " . DB_PREFIX . "subscriber ".
            " SET email = '" . $this->db->escape($data['email']) . "'"
        );

        return true;
    }

    public function deleteByEmail($email) {
        $this->db->query("DELETE FROM " . DB_PREFIX . "subscriber WHERE email = '" . $this->db->escape($email) . "'");

        return true;
    }

    public function getByEmail($email) {
        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "subscriber WHERE email = '" . $this->db->escape($email) . "'");

        return $query->row;
    }

    public function deleteSubscriber($subscriber_id) {
        $this->db->query("DELETE FROM " . DB_PREFIX . "subscriber WHERE subscriber_id = '" . (int)$subscriber_id . "'");
    }

    public function getSubscriber($subscriber_id) {
        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "subscriber WHERE subscriber_id = '" . (int)$subscriber_id . "'");

        return $query->row;
    }
}
?>